<template>
	<view class="box_one">
		<view class="bigbox">
			<view class="title">登录</view>
			<view class="onebox">
				<view class="input-box">
					<input type="text" placeholder="请输入用户名" v-model="username" />
				</view>
				<view class="input-box">
					<input type="password" placeholder="请输入密码" v-model="password"/>
				</view>
				<view ><button class="dlu" type="primary" @click="handleLogin">登录</button></view>
			</view>
			<view class="wenzi">
				<view class="texter">没有账号？</view>
				<view class="texts" @tap="toRegister">去注册</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				username: "",
				password: "",
				isPwdfocus: false
			}
		},
		methods: {
			handleLogin() {
				if (!this.username || !this.password) {
					uni.showToast({
						title: '请输入完整信息',
						icon: 'none'
					})
					return;
				}
				
				if (this.username === 'ljq' && this.password === '123456') {
					uni.showLoading({
						title: '登录中...'
					})
					setTimeout(() => {
						uni.hideLoading()
						uni.showToast({
							title: '登录成功'
						})
						uni.setStorage({
							key:'userName',
							data:username,
							success:function(){
								console.log("setStorage");
								console.log("setStorage--->data:"+this.username);
							}
						})
						uni.switchTab({
							url: "/pages/tabBar/tabcomponent/tabcomponent"
						})
					}, 1000)
				} else {
					uni.showToast({
						title: '密码错误，请重新输入',
						icon: 'none'
					});
					this.password = '';
					this.isPwdfocus = true;
				}
			},
			toRegister() {
				uni.navigateTo({
					url: '/pages/components/register/register'
				})
			}
		}
	}
</script>

<style>
	.box_one{
		width: 100%;
		min-height: 70vh;
		display: flex;
		justify-content: center;
		padding-top: 100rpx;
		box-sizing: border-box;
	}
	.bigbox{
		width: 70%;
		height: 400rpx;
		display: flex;
		justify-content: center;
		flex-direction: column;
		align-items: center;
		border-radius: 10rpx;
		border: 3rpx solid #e0e0e0;
	}
	.title{
		font-size: 36rpx;
		font-weight: bold;
		padding-top: 5px;
		margin:15rpx 0;
		
	}
	.onebox{
		width: 500rpx;
		height: 370rpx;
		line-height: 370rpx;
		align-items: center;
		flex-direction: column;
		display: flex;
		border-radius: 10rpx;
	}
	
	.input-box{
		display: flex;
		line-height: 50rpx;
		margin-top: 20rpx;
		border-radius: 9rpx;
		border: 2rpx solid #e0e0e0;
		width: 80%;
		align-items: center;
		height: 50rpx;
	}
	.dlu{
		width: 300rpx;
		height: 70rpx;
		line-height: 70rpx; /* 修复垂直居中 */
		
		color: #fff;
		font-size: 32rpx;
		border-radius: 8rpx;
		margin: 20rpx 0;
	}
	.wenzi{
		width: 80%;
		display: flex;
		justify-content: center;
		flex-direction: row;
		align-items: center;
	}
	.texter{
		width:130rpx;
		display: flex;
		justify-content: center;
		flex-direction: row;
		height: 50rpx;
		font-size: 20rpx;
		align-items: center;
		color: #bababa;
	}
	.texts{
		display: flex;
		justify-content: center;
		flex-direction: row;
		width: 200rpx;
		height: 50rpx;
		font-size: 20rpx;
		align-items: center;
		color: #2c66e5;
		margin-left: 10rpx;
	}
</style>
